<?php
namespace App\Module\User\Service;

use App\Constants\Constant;
use App\Model\Activity;
use Hyperf\Di\Annotation\Inject;
use Qbhy\HyperfAuth\AuthManager;

class ActivityService {

    /**
     * @Inject()
     * @var AuthManager $authManager
     */
    private $authManager;

    public function search($status,$pagesize){
        $query = Activity::query()->with(["resources",'users'])->latest("act_id");

        if(!empty($status)){
            $query->where("status",$status);
        }

        return $query->paginate($pagesize);
    }

    public function getById($id){
        return Activity::query()->with(["resources",'users'])->find($id);
    }

    public function mine($status, $pagesize){
        $query = $this->authManager->guard(Constant::USER)->user()->payments()->latest("pay_id")->with("activity");

        if(!empty($status)){
            $query->where("order_status",$status);
        }

        return $query->paginate($pagesize);
    }
}